<?php

declare(strict_types=1);

namespace app\model;

use app\model\base\BaseShortUrlModel;

/**
 * 
 *
 * @mixin \think\Model
 * @property int $id
 * @property string $params 用户名
 * @property string $url 跳转链接
 * @property int $agent_id 代理id
 * @property int $channel_id 渠道id
 * @property int $user_id 用户id
 * @property string $create_time
 * @property string $update_time
 */
class ShortUrl extends BaseShortUrlModel
{
    protected $json = ['params'];

    protected $jsonAssoc = true;


    public function getUrlAttr($value, $model)
    {

        if (strstr($value, 'http')) {
            return $value;
        }

        /** @var Config $config */
        $config = Config::query()->where('field', 'h5_host_url')->find();

        if (empty($config)) {
            return '没有配置h5_host_url';
        }

        $value = str_replace('/topup','',$value);

        return $config->value . $value;

    }

}
